﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace EWDTAssignment
{
    public partial class CustomerService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime day = DateTime.Today;
            
            DataTable dt = new DataTable();
            dt = App_Code.LiveChatSQL.ShowNameList(day);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListItem items = new ListItem(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString());
                if (CustomerNameList.Items.Contains(items))
                {
                    continue;
                }
                else{
                    CustomerNameList.Items.Add(items);
                }
            }
            if (IsPostBack)
            {
                DataTable newdt = App_Code.LiveChatLogic.Upload(App_Code.LiveChatSQL.uploadMessage(Convert.ToInt32(Session["CustomerChatID"]), day));

                GridView1.DataSource = newdt;
                GridView1.DataBind();
            }
            CustomerServiceChatTbx.Text = null;
        }

        protected void CustomerNameList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int accountID = 0;
            Session["CustomerChatID"]= CustomerNameList.SelectedItem.Value;
            accountID=Convert.ToInt32(Session["CustomerChatID"]);
            DateTime day = DateTime.Today;
            DataTable newdt = App_Code.LiveChatLogic.Upload(App_Code.LiveChatSQL.uploadMessage(accountID, day));

            GridView1.DataSource = newdt;
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = 1;
            int staffid = 1;
            string message = CustomerServiceChatTbx.Text;
            DateTime time = DateTime.Now;
            string type = "Staff";
            int a = 0;
            a = App_Code.LiveChatSQL.Say(id, staffid, time, message, type);
        }

        protected void CustomerNameList_TextChanged(object sender, EventArgs e)
        {
          
        }
    }
}